package net.slteam.base.support;

import net.slteam.base.ISLEnum;
import org.apache.ibatis.type.TypeHandlerRegistry;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * ClassName: SLEnumMybatisConfigurer
 * Description: ISLEnum 对Mybatis-Plus或Tk.Mybatis支持配置
 * date: 2022/9/9 11:13 PM
 *
 * @author calm
 * @since JDK 1.8
 */

@Configuration
public class SLEnumMybatisConfigurer {

    @Component
    @ConditionalOnClass(tk.mybatis.mapper.autoconfigure.ConfigurationCustomizer.class)
    public static class SLEnumTkMybatisConfigurer implements tk.mybatis.mapper.autoconfigure.ConfigurationCustomizer {
        @Override
        public void customize(org.apache.ibatis.session.Configuration configuration) {
            TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
            typeHandlerRegistry.register(ISLEnum.class, new SLEnumMybatisHandler());
        }
    }

    @Component
    @ConditionalOnClass(com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer.class)
    public class SLEnumMybatisPlusConfigurer implements com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer {

        @Override
        public void customize(com.baomidou.mybatisplus.core.MybatisConfiguration configuration) {
            TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
            typeHandlerRegistry.register(ISLEnum.class, new SLEnumMybatisHandler());
        }
    }

}
